/**
 * Created by 飞 on 2017/4/26.
 */
//封装获取组元素 开始
function getClass(clsName,content) {
    var result = [];
    content = content||document;
    var arr = content.getElementsByTagName("*");
    for (var i = 0 ;i < arr.length;i++){
        if (arr[i].className.indexOf(clsName)!= -1){
            result.push(arr[i]);
        }
    }
    return result;
}
//封装获取组元素 结束

//return to top begin
var oToTop = document.getElementById("to-top");
oToTop.className="";
oToTop.onclick = function () {
    var nowLocation = document.body.scrollTop||document.documentElement.scrollTop;
    if(nowLocation!=0){
        this.className = "selected";
    }
    var timer=setInterval(function(){//timer=2  返回值随机，未必是1起始
        window.scrollTo(0,nowLocation*=0.6); //attention window
        // console.log(nowLocation);
        // console.log(timer);
        if (nowLocation<=1){
            // console.log(document.body.scrollTop||document.documentElement.scrollTop);
            scrollTo(0,0);
            clearInterval(timer);
            oToTop.className="";//需要将消除放置在计时器内部，这样才可以使动画重复使用。此外，此处，不得使用this，因为使用this会指向window。
        }
        console.log(timer);
    },120);
    console.log(timer+"ha");
    // oToTop.className="";
};
//return to top finish

//today begin
//方法一
// var myDate = new Date();
// document.write("<div id=\"today\">"+myDate+"</div>");//add time important  错误 重复获取ID
// //方法二
setInterval(function(){
    var oDat = document.getElementById("date"),
        myDate = new Date();
    oDat.innerHTML= myDate;
},50);
// today finish/////

//audio control begin
var oMusic = document.getElementById("music"),
    oPlayer = document.getElementById("player"),
    oAudio = oPlayer.getElementsByTagName("audio")[0];
oMusic.onclick = function () {
    if(oAudio.paused){
        oAudio.play();
    }else{
        oAudio.pause();
    }
}//如何控制播放器
//audio control finish

//nav-sub display block begin
var oNavSub = document.getElementById("nav-sub");
var oNavLeft = document.getElementById("nav-left");
var oHomepages = getClass("homepages",oNavLeft)[0];
console.log(oHomepages);
oHomepages.onmouseover =function(){
    oNavSub.style.display = "block";
}
oHomepages.onmouseout = function () {
    oNavSub.style.display = "none";
}
//nav-sub display block finish